package com.bjqg.bjqg01.bjqg.dialog;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;

import com.bjqg.bjqg01.bjqg.utils.ToastUtil;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;

/**
 * Created by bjqg01 on 2018/9/3.
 */

public class DialogCallback extends StringCallback {
    IntentLoginDialog.Builder dialog;

    public DialogCallback(Context activity) {
        super();
        initDialog(activity);
    }

    private void initDialog(Context activity) {
        if (dialog == null) {
            dialog = new IntentLoginDialog.Builder(activity);
        }
    }

    @Override
    public void onStart(Request<String, ? extends Request> request) {
        super.onStart(request);
        if (dialog != null && !dialog.create().isShowing()) {
            dialog.create().show();
        }
    }

    @Override
    public void onSuccess(Response<String> response) {
        if (dialog != null && dialog.create().isShowing()) {
            dialog.create().dismiss();
            dialog = null;
        }
    }

    @Override
    public void onFinish() {
        super.onFinish();
        if (dialog != null && dialog.create().isShowing()) {
            dialog.create().dismiss();
            dialog = null;
        }
    }

    @Override
    public void onError(Response<String> response) {
        super.onError(response);
        if (dialog != null && dialog.create().isShowing()) {
            dialog.create().dismiss();
            dialog = null;
        }
    }

}
